package com.zjjk.transfer.app;

import com.zjjk.transfer.source.entity.SourceDish;
import com.zjjk.transfer.source.entity.SourceOrderDetail;
import com.zjjk.transfer.source.service.SourceDishService;
import com.zjjk.transfer.source.service.SourceOrderDetailService;
import com.zjjk.transfer.target.entity.TargetOrderDetail;
import com.zjjk.transfer.target.service.TargetOrderDetailService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
    public class OrderDetailTransfer extends BaseTransfer<SourceOrderDetail, TargetOrderDetail, SourceOrderDetailService, TargetOrderDetailService>{
    @Autowired
    private SourceDishService sourceDishService;

    @Override
    protected TargetOrderDetail convert(SourceOrderDetail source) {
        TargetOrderDetail target = new TargetOrderDetail();
        BeanUtils.copyProperties(source,target);
        target.setId(Long.valueOf(source.getId()));
        target.setOrderId(Long.valueOf(source.getOrderId()));
        target.setDishId(Long.valueOf(source.getDishId()));
        SourceDish byId = sourceDishService.getById(source.getId());
        if (null != byId){
            target.setDishName(byId.getName());
            target.setPicture(byId.getPicture());
            target.setDishCategoryId(Long.valueOf(byId.getMealType()));
        }
        target.setUserId(String.valueOf(source.getUserId()));
        target.setMealBoxFee(source.getMealsFee());
        return target;
    }
}
